#include <stdio.h>
#include <stdlib.h>
#include "../AT/at.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

static void at_test(void)
{
	const char* num_string[] = {
		"12345678",
		"-123.45678",
		"+123.45678",
		"  123.45678",
		".123456789",
		"123.45678 ",
		"123..45678",
		"123.456a",
		"a123.456",
	};
	unsigned char i = 0;
	const char* src = "123456789";
	char upper[] = "a1B2c3D4efghi jklm t"; 
	char copy_dest[16];
	char* one = "abcd1234";
	char* two = "abcd1234";
	char* three = "abcdefg";
	
	const char ats[] = "AT ver\n AT VOLCLB 12.0\n AT HEATTMP 0.0 35.0\n AT MOTOR 35.0 15.0\nA T VOLCLB 12.0\nAT DEBUG 1\n";
	AT_PARSE_STATUS at_parse_status;
	
	for(i=0; i<sizeof(num_string)/sizeof(const char*); ++i)
	{
		printf("\t%s = %.8f\n", num_string[i], str_to_float(num_string[i]));
	}
	printf("str_to_float() PASS...\r\n\r\n");
	
	
	copy_str_len(src, copy_dest, 6); 
	printf("copy len: %s %d\r\n", copy_dest);
	copy_str_len(src, copy_dest, 15); 
	printf("copy len: %s %d\r\n", copy_dest);
	printf("copy_str_len() PASS...\r\n\r\n");
	
	
	to_upper(upper, upper);
	printf("Upper: %s\r\n", upper);
	printf("to_upper() PASS...\r\n\r\n");
	
	
	printf("str_eq: %s=%s(%d)  %s=%s(%d)\r\n", one, two, str_eq(one, two), one, three, str_eq(one, three));
	printf("str_eq() PASS...\r\n\r\n");
	
	
	for(i=0; i<sizeof(num_string)/sizeof(const char*); ++i)
	{
		printf("\t%s is number? %d\n", num_string[i], is_number(num_string[i]));
	}
	printf("is_number() PASS...\r\n\r\n");
	
	for(i=0; i<sizeof(ats); ++i)
	{
		AT_PARSE_RESULT sta = at_parse(ats[i], &at_parse_status);
		if(AT_PARSE_RESULT_ERROR==sta)
		{
			printf("Error!\n");
		}else if(AT_PARSE_RESULT_SUCCESS==sta)
		{
			float* param;
			AT_CMD_TYPE type = at_process();
			param = get_at_param();
			printf("Success %d(%.2f,%.2f,%.2f,%.2f)%s %d\n", type, param[0], param[1], param[2], param[3], get_type_name(type), at_type_valid(type));
		}
	}
}

int main(int argc, char *argv[]) {
	
	printf("Test Debug...\r\n\r\n");
	
	at_test();
	
	return 0;
}
